package com.acctrue.zentao.entity;

import com.acctrue.zentao.utils.StringUtils;
import com.intellij.ide.util.PropertiesComponent;
import org.jetbrains.annotations.NotNull;

import java.util.Optional;

/**
 * 禅道配置实体类
 *
 * @author: 孙炯炯
 * @since: 2023/8/18
 **/
public class ZentaoSettingEntity {
    public static final String ZENTAO_SERVER_ADDRESS = "ZENTAO_SERVER_ADDRESS";
    public static final String ZENTAO_USERNAME = "ZENTAO_USERNAME";
    public static final String ZENTAO_PASSWORD = "ZENTAO_PASSWORD";
    public static final String ZENTAO_SUCCESS = "ZENTAO_SUCCESS";

    private ZentaoSettingEntity(@NotNull PropertiesComponent prop) {
        initParam(prop);
    }

    public static Optional<ZentaoSettingEntity> getEntity(PropertiesComponent prop) {
        if (prop == null) {
            return Optional.empty();
        }
        return Optional.ofNullable(new ZentaoSettingEntity(prop));
    }

    private String serverAddress;
    private String userName;
    private String password;
    private Boolean success=false;

    public String getServerAddress() {
        return serverAddress;
    }

    public void setServerAddress(String serverAddress) {
        this.serverAddress = serverAddress;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void initParam(@NotNull PropertiesComponent prop) {
        this.serverAddress = StringUtils.getString(prop.getValue(ZENTAO_SERVER_ADDRESS));
        this.userName = StringUtils.getString(prop.getValue(ZENTAO_USERNAME));
        this.password = StringUtils.getString(prop.getValue(ZENTAO_PASSWORD));
        if(Boolean.TRUE.toString().equals(prop.getValue(ZENTAO_SUCCESS))){
            success=true;
        }else{
            success=false;
        }
    }
}
